import { clearObject, deepCopyObj } from '../../../assets/js/help.js'
export default {
  data() {
    return {
      value3: ''
    }
  },
  created() {
    
  },
  filters: {

  },
  methods: {
    getList() {
      let params = $.extend({}, this.searchParams, this.otherParams);
      this.list(params);
    },
    list(aparams) {
      let self = this,
        params = {
          page: this.pageNumber,
          rp: this.pageSize
        };
      params = $.extend({}, params, aparams);

      API.score.reportList(params)
        .then(res => {
          let data = res.data,
            list = data.rows;
          self.tbodysInfo = list;
          self.total = data.total;
        }, err => { })
    },
    toCreate(report) {
      var self = this;
      let params = {  //  重新生成需要传的参数
        reportDimension: self.searchParams.reportDimension,
        parkId: report.parkId,
        statDateYear: report.statDateYear,
        statDateMonth: report.statDateMonth,
        statDateDay: report.statDateDay
      };
      if(params.reportDimension==null){
        params.reportDimension='day';
      }
      if(params.reportDimension=='custom'){
          var dateArr = report.date4ExportStr.split('至');
          var statDateFromStr = dateArr[0];
          var statDateToStr = dateArr[1];
          params.statDateFromStr = statDateFromStr;
          params.statDateToStr = statDateToStr;
      }

      self.showDialog("确认重新生成?", '', function () {
        API.score.reportRecreate(params).then(res => {
          self.showToast('重新生成成功', false);
          self.getList();
        }, err => { })
      });
    },
    exportReport() {
      let self = this;
      let theadsArr = []
      for(let i = 0; i<self.theadsInfo.length; i++){
        if(self.theadsInfo[i].checked){
          theadsArr.push(self.theadsInfo[i].prop)
        }
      }
      let params = {
        meterList: theadsArr.join(',')
      };
      params = $.extend({}, params, this.searchParams, this.otherParams);

      switch (params.reportDimension) {
          case 'day':
              //params['statDateFromStr'] = moment(params.statDateFromStr, 'YYYY-MM-DD').startOf('day').format('YYYY-MM-DD HH:mm:ss');
              //params['statDateToStr'] = moment(params.statDateToStr, 'YYYY-MM-DD').endOf('day').format('YYYY-MM-DD HH:mm:ss');
              break;
          case 'month':
              params['statDateFromStr'] = moment(params.statDateFromStr, 'YYYY-MM').startOf('month').format('YYYY-MM-DD HH:mm:ss');
              params['statDateToStr'] = moment(params.statDateToStr, 'YYYY-MM').startOf('month').format('YYYY-MM-DD 00:00:00');
              break;
          case 'year':
              params['statDateFromStr'] = moment(params.statDateFromStr, 'YYYY').startOf('year').format('YYYY-MM-DD HH:mm:ss');
              params['statDateToStr'] = moment(params.statDateToStr, 'YYYY').startOf('year').format('YYYY-MM-DD 00:00:00');
              break;
          case 'custom':
              params['statDateFromStr'] = params.statDateFromStr;
              params['statDateToStr'] = params.statDateToStr;
              break;
          default:
      }

      self.showDialog("确认导出该报表?", '', function () {
        self.toExportAsync('score/deduct/report/export.do', params);
      });
    },
    exportReportDetail(report) {
      let self = this;
      let params = {
        parkIds: report.parkId
      };
      var date = report.date4ExportStr;
      switch (self.searchParams.reportDimension) {
        case 'day':
          params['query_payTimeFrom'] = moment(date, 'YYYY-MM-DD').startOf('day').format('YYYY-MM-DD HH:mm:ss');
          params['query_payTimeTo'] = moment(date, 'YYYY-MM-DD').endOf('day').format('YYYY-MM-DD HH:mm:ss');
          break;
        case 'month':
          params['query_payTimeFrom'] = moment(date, 'YYYY-MM').startOf('month').format('YYYY-MM-DD HH:mm:ss');
          params['query_payTimeTo'] = moment(date, 'YYYY-MM').endOf('month').format('YYYY-MM-DD HH:mm:ss');
          break;
        case 'year':
          params['query_payTimeFrom'] = moment(date, 'YYYY').startOf('year').format('YYYY-MM-DD HH:mm:ss');
          params['query_payTimeTo'] = moment(date, 'YYYY').endOf('year').format('YYYY-MM-DD HH:mm:ss');
          break;
        case 'custom':
          params['query_payTimeFrom'] = date.split("至")[0] + " 00:00:00";
          params['query_payTimeTo'] = date.split("至")[1] + " 23:59:59";
          break;
        default:
          params['query_payTimeFrom'] = moment(date, 'YYYY-MM-DD').startOf('day').format('YYYY-MM-DD HH:mm:ss');
          params['query_payTimeTo'] = moment(date, 'YYYY-MM-DD').endOf('day').format('YYYY-MM-DD HH:mm:ss');
          break;
      }

      self.showDialog("确认导出该报表?", '', function () {
        self.toExportAsync('score/deduct/report/export.do', params);
      });
    },
  }
}